<template>
	<div>
		<div class="h2">场地预约时间管理</div>
		<div>
			<el-table ref="tableList" :data="data1" v-loading="loading" border :max-height="tableHeight" highlight-current-row style="width: 100%;">
				<el-table-column prop="week" v-for="(item,o) in data" :key="o" :label="item.week" min-width="150">
					 <template slot="header" slot-scope="scope">
					        {{ item.week }}<a-button type="primary" class="addbtn" @click="addList(item.num)">新增</a-button>
					      </template>
					<template slot-scope="scope">
						<div class="list" v-for="(item,i) in weekList.filter((m,n)=>m.WeekDay==item.num)" :key="i">
						<span class="listspan">{{ item.StartTime }} - {{ item.EndTime }}</span><i @click="modifyList(item)" class="el-icon-edit-outline"></i>
						<i @click="deleteList(item,1)" style="color:red;font-size:20px;" class="el-icon-delete"></i>
						</div>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<add :text="text" :weeknum="weeknum" v-show="addIf" @closeFun="closeFun"></add>
	</div>
</template>

<script>
import add from './add';
import Func from '@/utils/func';
import moment from 'moment';
import Cache from '@/utils/cache';
import { DoGetListVenueTimeTable, DeleteVenueType,DeleteVenueTimeTable } from '@/api/follow';
const data = [];
export default {
	components: {
		add
	},
	data() {
		return {
			data1:[1],
			data:[
				{
					week:'周一',
					num:1
				},
				{
					week:'周二',
					num:2
				},
				{
					week:'周三',
					num:3
				},
				{
					week:'周四',
					num:4
				},
				{
					week:'周五',
					num:5
				},
				{
					week:'周六',
					num:6
				},
				{
					week:'周日',
					num:7
				},
			],
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			pagination: {
				currentPage: 1,
				pageSize: this.global.pageSize,
				pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
				showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
			},
			addIf: false,
			text: {},
			loading: false,
			values: {},
			tableHeight: parseFloat(window.innerHeight - 160),
			requestUrl: this.global.requestUrl,
			token: Cache.get('token'),
			isAssistantList: this.global.isAssistantList,
			weeknum:0,
			weekList:[]
		};
	},
	computed: {},
	created() {
		this.getList();
	},
	mounted() {},
	methods: {
		moment,
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination.currentPage = 1;
				this.values = values;
				this.getList();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		handleSizeChange(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		async getList() {
			console.log(1)
			this.loading = true;
			let data = {};
			data.venueID = this.$route.query.id
			let res = await DoGetListVenueTimeTable(data);
			this.loading = false;
			this.weekList = res.data.data;
		},
		addList(num) {
			this.weeknum = num
			this.text = {};
			this.addIf = !this.addIf;
		},
		modifyList(text) {
			text = { ...text,time: new Date() }
			this.addIf = !this.addIf;
			this.text = text;
		},
		deleteList(text, type) {
			let that = this;
			let content = '';
			switch (type) {
				case 1:
					content = '您确定删除该数据吗?';
					break;
			}
			this.$confirm({
				title: '提示',
				content: content,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res={}
					res = await DeleteVenueTimeTable(data)
					console.log(res.data)
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		closeFun(data) {
			this.addIf = false;
			if (data == 1) {
				this.getList();
			}
		}
	}
};
</script>

<style lang="less" scoped>
.list{
	line-height:40px;
}
.el-icon-edit-outline{
	color:blue;
	font-size:20px;
	vertical-align: text-bottom;
}
/deep/.el-table th.is-leaf {
	background: #fafafa;
}
/deep/.el-table td,
/deep/.el-table th {
	padding: 5px;
}
.addbtn{
	margin-left:10px;
	width:46px;
	height:24px;
	padding:0px;
	font-size:12px;
}
</style>
